<template>
    <div class="icons">
        <swiper :options="swiperOption">
            <swiper-slide v-for='(page, index) of pages' :key="index" >
                <div class="icon" v-for='item of page' :key="item.id">
                    <div class="icon-img"><img class="icon-img-content" :src="item.imgUrl"></div>
                    <p class="icon-desc">{{item.desc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  //   定义一组数据，必须是对象，他的返回值是正真数据的内容 定义一个iconList数组 ，数组里存放的是一个个小图标的内容
  // 每一个图标都有一个编号id，
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  //   计算属性
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<!--height: 0
        padding-bottom: 50% 先设置height为0 在设置为宽高比为2:1 padding-bottom: 50%表示是高的50% -->
<!-- .icon
            float: left 设置浮动
            width: 25% 宽是屏幕的宽的25%
            padding-bottom: 25% 高是宽的50%的50% 也就是25%
        当:options="swiperOption" 未定义时 显示Property or method "swiperOption" is not defined -->
<style lang="stylus" scoped>
    @import '../../../assets/style/varibles.styl'
    @import '../../../assets/style/mixins.styl'
    .icons >>>.swiper-container
        height: 0
        padding-bottom: 50%
    .icons
        margin-top: .1rem
        over-flow: hidden
        height: 0
        padding-bottom: 50%
        .icon
            height: 0
            position: relative
            overflow: hidden
            float: left
            width: 25%
            padding-bottom: 25%
            .icon-img
                box-sizing: border-box
                padding: .1rem
                width: 100%
                position:absolute
                top: 0
                left: 0
                right: 0
                bottom: .44rem
                .icon-img-content
                    height: 100%
                    display: block
                    margin: 0 auto
            .icon-desc
                left: 0
                right: 0
                bottom: 0
                height: .44rem
                line-height:  .44rem
                color: $iconTextColor
                text-align: center
                padding-top: 1.3rem
                ellipsis()

</style>
